package com.example.designpatterns.behavioral.momento;

/**
 * 客户端代码（具体使用）
 *
 * @author scott
 */
public class Client {

    public static void main(String[] args) {
        Document currentDocument = new Document();
        HistoryManager historyManager = new HistoryManager(currentDocument);

        // 设置初始内容
        currentDocument.setContent("This is the initial content.");
        printCurrentContent(currentDocument);

        // 保存当前状态
        historyManager.saveState();
        // 修改内容
        currentDocument.setContent("Updated content 1");
        printCurrentContent(currentDocument);

        // 保存当前状态
        historyManager.saveState();
        // 修改内容
        currentDocument.setContent("Updated content 2");
        printCurrentContent(currentDocument);

        // 撤销操作
        historyManager.undo();
        printCurrentContent(currentDocument);

        // 重做操作
        historyManager.redo();
        printCurrentContent(currentDocument);
    }

    private static void printCurrentContent(Document document) {
        System.out.println("Current content: " + document.getContent());
    }

}
